package com.springapp.fed.mvc.controllers;

import com.springapp.fed.domain.model.UserData;
import com.springapp.fed.mvc.facade.FraudDetectionFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/fraud")
public class FraudDetectionController {
    @Autowired
    FraudDetectionFacade fraudDetectionFacade;

	@RequestMapping(value ="detect",method = RequestMethod.POST)
	public String printWelcome(Model model,HttpServletRequest request,@ModelAttribute UserData userData) {
        Map<String,List<String>> userdata2=new HashMap<String, List<String>>();
        userdata2.put("firstName", Arrays.asList(request.getParameterValues("firstName")));
        userdata2.put("lastName", Arrays.asList(request.getParameterValues("lastName")));
        userdata2.put("birthday", Arrays.asList(request.getParameterValues("birthday")));
        userdata2.put("mobile", Arrays.asList(request.getParameterValues("mobile")));
        userdata2.put("email", Arrays.asList(request.getParameterValues("email")));
		model.addAttribute("userdata", userdata2);
        fraudDetectionFacade.processFraudDetection(model);
		return "result";
	}
}